package com.kws.merchant.service.impl;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kws.merchant.domain.Specification;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.merchant.mapper.SpecificationMapper;
import com.kws.merchant.service.SpecificationService;
import com.kws.merchant.util.FileUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 规格信息表(Specification)表服务实现类
 *
 * @author yxy
 * @since 2024-10-22 11:03:44
 */
@Service("specificationService")
public class SpecificationServiceImpl extends ServiceImpl<SpecificationMapper, Specification> implements SpecificationService {

    @Resource
    private SpecificationMapper specificationMapper;


    @Override
    public List<Specification> listByType(Integer type) {
        List<Specification> list = this.list(Wrappers.<Specification>lambdaQuery().eq(Specification::getType, type));
        list.forEach(x->{
            x.setImg(FileUtil.fixFileName()+x.getImg());
        });
        return list;
    }

    @Override
    public Specification detailById(Long id) {
        Specification specification = this.getById(id);
        if (ObjectUtils.isEmpty(specification)){
            throw new RuntimeException("规格信息错误");
        }
        specification.setImg(FileUtil.fixFileName()+specification.getImg());
        return null;
    }

    /**
     * 查询商品规格
     * @param id
     * @return
     */
    @Override
    public List<Specification> listByGoodsId(Long id) {
        List<Specification> list = this.list(Wrappers.<Specification>lambdaQuery().eq(Specification::getGoodsId, id));
        return list;
    }
}
